trigger OORBookingDatesUpdates on Booking_Dates__c (after Insert,after Update) {

       //Trigger Name: OORBookingDatesUpdates 
       //Trigger Purpose : Trigger to Update Booking Details on Opportunity and Split Order
       //Project Name: OOR Phase 2
       //Author: Accenture IDC
       List<Booking_Dates__c>  bookDateList = new List<Booking_Dates__c>();
       Set<String> YearString = new Set<String>();
       String YearNumber;
        for(Booking_Dates__c bookdaterecord:Trigger.new){
           if(Trigger.ISUPDATE){
            if(bookdaterecord.Booking_Closing_Date__c != NULL && (bookdaterecord.Booking_Closing_Date__c != Trigger.OldMap.get(bookdaterecord.id).Booking_Closing_Date__c)){
                  bookDateList.add(bookdaterecord);
                  YearString.add(bookdaterecord.Booking_Closing_Year1__c); 
                  YearNumber = String.ValueOf(Integer.valueOf(bookdaterecord.Booking_Closing_Year1__c) + 1); 
                  YearString.add(YearNumber);
            }
            }
            if(Trigger.ISINSERT){
                if(bookdaterecord.Booking_Closing_Date__c != NULL){
                    bookDateList.add(bookdaterecord);
                    YearString.add(bookdaterecord.Booking_Closing_Year1__c);
                    YearNumber = String.ValueOf(Integer.valueOf(bookdaterecord.Booking_Closing_Year1__c) + 1); 
                    YearString.add(YearNumber);  
                }                    
            }
        }
        
        //Batch Class called to update the related opportunities with Booking Closing Date
        If(bookDateList.size()>0){
            ID SFAOORLeadOrderAdvertiserRecordTypeID = RecordTypeHelper.GetRecordTypeID('Opportunity', 'SFA-OOR Lead Order');       
            ID SFAOORRenewalecordTypeID = RecordTypeHelper.GetRecordTypeID('Opportunity', 'SFA-OOR Renewals');
            
            OOROrderBookingDatesUpdate job = new OOROrderBookingDatesUpdate();
            job.YearStringBatch = YearString;
            job.Query = 'Select Id,Order_Completion_Date__c,CloseDate,Order_Date_SOLO__c,SOLO_Submitted_Date__c,Booking_Closing_Date__c from Opportunity Where  (StageName = \'' + 'Solo Order Pending' + '\' OR StageName = \'' + 'Closed' + '\' OR StageName = \'' + 'Lost (enter reason)' + '\' OR StageName = \'' + 'Signed Contract'+ '\') AND (RecordTypeId=\''+SFAOORLeadOrderAdvertiserRecordTypeID+ '\' OR RecordTypeId =\''+SFAOORRenewalecordTypeID+ '\') AND  Booking_Year__c IN: YearStringBatch';
            Database.executeBatch(job, 100);

        }
   
}